/*
 * Copyright Aristool AG Switzerland
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package org.opprua.tidy.conversion;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * TODO: add Java doc
 * 
 * Prepared for first commit: 15.07.2007
 * 
 * @author Lin Li
 */
class CTLong extends ChangeType<Long> {

  private static SingleChanger<Long>[] changers = null;

  public CTLong() {
    super(Long.class, 0L);
  }

  @Override
  @SuppressWarnings("unchecked")
  public SingleChanger<Long>[] getchangers() {
    if (changers == null) {
      changers = (SingleChanger<Long>[]) new SingleChanger[] {
                  new SingleChanger<Long>(String.class) {

                    public Long change(Object data) {
                      return Long.parseLong((String) data);
                    }
                  }, new SingleChanger<Long>(BigDecimal.class) {

                    public Long change(Object data) {
                      return ((BigDecimal) data).longValue();
                    }
                  }, new SingleChanger<Long>(BigInteger.class) {

                    public Long change(Object data) {
                      return ((BigInteger) data).longValue();
                    }
                  }, new SingleChanger<Long>(Integer.class) {

                    public Long change(Object data) {
                      return ((Integer) data).longValue();
                    }
                  }, new SingleChanger<Long>(Short.class) {

                    public Long change(Object data) {
                      return ((Short) data).longValue();
                    }
                  }, new SingleChanger<Long>(java.util.Date.class) {

                    public Long change(Object data) {
                      return ((java.util.Date) data).getTime();
                    }
                  }, new SingleChanger<Long>(java.sql.Date.class) {

                    public Long change(Object data) {
                      return ((java.sql.Date) data).getTime();
                    }
                  }, new SingleChanger<Long>(java.sql.Time.class) {

                    public Long change(Object data) {
                      return ((java.sql.Time) data).getTime();
                    }
                  }, new SingleChanger<Long>(java.sql.Timestamp.class) {

                    public Long change(Object data) {
                      return ((java.sql.Timestamp) data).getTime();
                    }
                  } };
    }
    return changers;
  }
}